package restaurant.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.handlers.BeanListHandler;

import restaurant.dao.BoardDao;
import restaurant.pojo.Board;
import restaurant.utils.BaseDao;

public class BoardDaoImpl extends BaseDao implements BoardDao {

	@Override
	public int addBoard(String name) throws SQLException {
		String sql = "insert into board (id,name) values(null,?)";
		int i = qr.update(sql, name);
		// 注释
		String sql2 = "insert into board (id,name) values(null,?)";
		return i;
	}

	@Override
	public int delBoard(String id) throws SQLException {
		String sql = "delete from board where id = ?";
		int i = qr.update(sql, id);
		return i;
	}

	@Override
	public List<Board> showBoard() throws SQLException {
		String sql = "select * from board";
		List<Board> board = qr.query(sql, new BeanListHandler<Board>(Board.class));
		return board;
	}

	@Override
	public int update(String id, String state) throws SQLException {
		String sql = "update board set state = ?,btime=now() where id = ?";
		int i = qr.update(sql, state,id);
		return i;
	}

	@Override
	public List<Board> find(String param) throws SQLException {
		param = "%"+ param +"%";
		String sql = "select * from board where name like ?";
		List<Board> board = qr.query(sql, new BeanListHandler<Board>(Board.class), param);
		return board;
	}

}
